﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using Lamex.Library;
using Lamex.Library.CommonClass;
using Lamex.Base;

namespace Lamex.mTube.UI
{
    public partial class frmTube_Laser_Cutting : frmBaseChild
    {
        Lamex.mNC.ucControls.ucShowPic ucShowPicList = null;
        public frmTube_Laser_Cutting()
        {
            InitializeComponent();
        }

        private void frmTube_Laser_Cutting_Resize(object sender, EventArgs e)
        {
            splitContainerControl1.SplitterPosition = this.Width * 2 / 5;
            splitContainerControl2.SplitterPosition = this.Height * 1 / 3;
            splitContainerControl3.SplitterPosition = this.Width * 3 / 10;
        }

        private void groupControl1_CustomButtonClick(object sender, DevExpress.XtraBars.Docking2010.BaseButtonEventArgs e)
        {
            if(e.Button.Properties.ToolTip== "任务清单刷新")
            {
                SplashScreenTool.ShowSplashScreen(typeof(WaitForm1));
                //DataTable dt = Lamex.mNC.Common.GetDataTable.Get_OrderData(System.DateTime.Now.ToString());
                DataTable dt = new DataTable();
                string sqlWhere = " and DE.Product_TS like '%" + DateTime.Now.ToString("yyyy-MM-dd") + "%'";
                string sql = @" select distinct de.Order_Number,de.Product_TS,DR.MODULE_NAME,left(de.Part_No,8)+'00' Part_No_Weld,de.Part_No,de.Drawing_No,sum(de.Part_QTY) Part_QTY FROM [LamexMESManager].[dbo].[Transfer_Part_Detailed] DE
 JOIN [LamexMESManager].[dbo].[IE_Part_Routing] RO on RO.Part_No=DE.Part_No
 JOIN [LamexMESManager].[dbo].[IE_Routing_Combination] CO ON RO.GROUP_CODE=CO.GROUP_CODE AND CO.ROUTING_CODE like '%P05%' 
 LEFT JOIN [LamexMESManager].[dbo].[NC_PN_AL_Detail_Drawing] DR ON DR.DRAWING_NO=DE.Drawing_No
 LEFT JOIN [LamexMESManager].[dbo].[NC_PN_AL_Manufacture_Convert_Record] CR ON CR.PART_NO=DE.Part_No AND CR.FOLLOW_NO=DE.Order_Number 
where 1=1 AND CR.PART_NO IS NULL AND CR.FOLLOW_NO IS NULL " + sqlWhere + "  group by  de.Product_TS,de.Order_Number,de.Part_No,de.Drawing_No,DR.MODULE_NAME ORDER BY DE.Order_Number";
                dt = BaseBuildSql.GetDataTableBySql(sql);
                gridMainData.DataSource = dt;

                ////每次刷新自动计算gridcontrol宽度
                //int width_Sums = 0;
                //this.gvMainData.OptionsView.ColumnAutoWidth = false;
                //for (int i = 0; i < gvMainData.Columns.Count; i++)
                //{
                //    this.gvMainData.BestFitColumns();
                //    this.gvMainData.Columns[i].BestFit();//自动列宽
                //    width_Sums += gvMainData.Columns[i].Width;
                //}
                //splitContainerControl1.SplitterPosition = width_Sums + 110;
                SplashScreenTool.CloseSplashScreen();
            }
        }

        private void gridMainData_Click(object sender, EventArgs e)
        {
            gc_ShowPicture.Controls.Clear();
            int iRow = gvMainData.FocusedRowHandle;
            string DWGNo = gvMainData.GetRowCellDisplayText(iRow, "Drawing_No").ToString();//图纸号
            string PartNo = gvMainData.GetRowCellDisplayText(iRow, "Part_No").ToString();//物料号
            List<string> listPic = new List<string>();
            listPic = Lamex.mNC.Common.GetShowPic.ShowPic_STD(DWGNo, PartNo);
            if (listPic.Count > 0)
            {
                ucShowPicList = new Lamex.mNC.ucControls.ucShowPic();
                ucShowPicList.LoadImageList(listPic);
                ucShowPicList.Dock = DockStyle.Fill;
                gc_ShowPicture.Controls.Add(ucShowPicList);
            }
        }
    }
}